﻿#region 文件信息

// FileName: SoCafeShop/Sohobloo.SoMcCoffee.Data/EntityConfigurationBase.cs
// Author: Sohobloo
// CreateTime: 2013/06/30 2:39
// UpdateTime: 2013/06/30 3:41

#endregion

#region 引用

using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using Sohobloo.SoMcCoffee.Public.Entity;

#endregion

namespace Sohobloo.SoMcCoffee.Data
{
    public abstract class EntityConfigurationBase<T> : EntityTypeConfiguration<T>, IEntityMapper where T : EntityBase
    {
        #region 构造

        protected EntityConfigurationBase()
        {
            Configurate();
        }

        #endregion 构造

        #region 方法

        public void RegistTo(ConfigurationRegistrar configurations)
        {
            configurations.Add(this);
        }

        public virtual void Configurate()
        {
            HasKey(e => e.Id);
            Property(e => e.CreateUser).IsRequired().HasMaxLength(50);
            Property(e => e.CreateTime).IsRequired();
            Property(e => e.UpdateUser).IsRequired().HasMaxLength(50);
            Property(e => e.UpdateTime).IsRequired();
            Property(e => e.Timestamp).IsRequired().IsRowVersion();
        }

        #endregion 方法
    }
}